package com.atguigu.security.custom;

import com.atguigu.common.utils.MD5;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Component;

/**
 * 自定义密码加密组件
 */
@Component
public class CustomMd5PasswordEncoder implements PasswordEncoder {
    /**
     * 密码加密
     * @param rawPassWord
     * @return
     */
    @Override
    public String encode(CharSequence rawPassWord) {
        return MD5.encrypt(rawPassWord.toString());
    }

    /**
     *判单密码是否相等。
     * @param rawPassWord 原始的密码
     * @param encodedPassword 输入的密码
     * @return
     */
    @Override
    public boolean matches(CharSequence rawPassWord, String encodedPassword) {
        return encodedPassword.equals(MD5.encrypt(rawPassWord.toString()));
    }
}
